import Mock from 'mockjs'
import INTELLIGENCES from './fakeData/INTELLIGENCES.js' // '../../../public/fakeData/INTELLIGENCES.js' 

const Random = Mock.Random

Random.extend({
  intelligencesList: function(data) {
    let list = INTELLIGENCES.data
    return this.pick(list)
  }
})

const targetAdminIntelligences = function (query) {
  let key = Object.entries(query)[0][0]
  let value = Object.entries(query)[0][1]
  let targets = INTELLIGENCES.data.filter((item) => {
    return item[key] === value
  })
  return targets
}

export function getAdminIntelligencesMock(Mock, url, query) {
  return Mock.mock({
    code: 0,
    msg: '',
    data: {
      page: `${query.pageIndex}`,
      limit: `${query.pageSize}`,
      total: 30,
      [`list|${query.pageSize}`]: [ '@intelligencesList' ],
      colData: INTELLIGENCES.colData.map((item) => {
        return {
          ...item,
          filterable: true,
          necessary: true,
          type: 'input'
        }
      })
    } 
  }) 
} 

export function findAdminIntelligencesMock(Mock, url, query) {
  return Mock.mock({
    code: 0,
    msg: '',
    data: {
      'list': targetAdminIntelligences(query)
    } 
  }) 
}